package com.yida.gwj.basis.controller;

import com.yida.common.core.utils.StringUtils;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.gwj.basis.domain.GwjInitBusinessHouse;
import com.yida.gwj.basis.domain.dto.GwjInitBusinessHouseDTO;
import com.yida.gwj.basis.service.IGwjInitBusinessHouseService;
import com.yida.gwj.basis.service.IGwjInitBusinessService;
import com.yida.gwj.common.utils.GwjConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 小区基础数据初始化（基础数据管理模块）通用Controller
 *
 * @author lqq
 * @date 2022-11-15
 */
@RestController
@RequestMapping("/business")
public class GwjInitBusinessController extends BaseController {

	@Autowired
	private IGwjInitBusinessService businessService;

	@Autowired
	private IGwjInitBusinessHouseService businessHouseService;

	/**
	 * 初始化获取拉取过的楼栋`
	 */
	@GetMapping("/existBuild/{areaId}/{buildCode}")
	public AjaxResult existBuild(@PathVariable Long areaId, @PathVariable String buildCode) {
		return AjaxResult.success(businessService.getExistBuild(areaId, buildCode));
	}

	/**
	 * 房屋图标显示（所以房屋）
	 */
	@GetMapping("/allHouse/{bizId}/{buildCode}")
	public AjaxResult allHouse(@PathVariable Long bizId, @PathVariable String buildCode) {
		GwjInitBusinessHouse businessHouse = new GwjInitBusinessHouse();
		businessHouse.setBizId(bizId);
		businessHouse.setBuildCode(buildCode);
		List<GwjInitBusinessHouse> list = businessHouseService.getList(businessHouse);
		if (StringUtils.isEmpty(list)) {
			return AjaxResult.success(new ArrayList<>());
		}
		return AjaxResult.success(GwjConvertUtil.convertList(list, GwjInitBusinessHouseDTO.class));
	}
}
